package com.xuetang.controller.admin;

import com.xuetang.entity.AdminUser;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import jakarta.servlet.http.HttpSession;

/**
 * 管理员控制器
 */
@Controller
@RequestMapping("/admin")
public class AdminController {

    /**
     * 后台首页
     */
    @GetMapping({ "", "/" })
    public String index(HttpSession session, Model model) {
        // 获取当前登录的管理员用户
        AdminUser adminUser = (AdminUser) session.getAttribute("adminUser");
        model.addAttribute("user", adminUser);
        return "admin/index";
    }

    /**
     * 登录页面
     */
    @GetMapping("/login")
    public String login() {
        return "admin/login";
    }

    /**
     * 用户管理页面
     */
    @GetMapping("/users")
    public String users(HttpSession session, Model model) {
        // 获取当前登录的管理员用户
        AdminUser adminUser = (AdminUser) session.getAttribute("adminUser");
        model.addAttribute("user", adminUser);
        return "admin/users";
    }

    /**
     * 角色管理页面
     */
    @GetMapping("/roles")
    public String roles(HttpSession session, Model model) {
        // 获取当前登录的管理员用户
        AdminUser adminUser = (AdminUser) session.getAttribute("adminUser");
        model.addAttribute("user", adminUser);
        return "admin/roles";
    }

    /**
     * 管理员账户管理页面
     */
    @GetMapping("/admins")
    public String admins(HttpSession session, Model model) {
        // 获取当前登录的管理员用户
        AdminUser adminUser = (AdminUser) session.getAttribute("adminUser");
        model.addAttribute("user", adminUser);
        return "admin/admins";
    }
}